<!--店铺文章页面-->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div>
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item prop="category">
          <ren-select v-model="dataForm.category" dict-type="category" placeholder="请选择文章分类"></ren-select>
        </el-form-item>
        <el-form-item prop="pub">
          <ren-select v-model="dataForm.pub" dict-type="pub" placeholder="请选择文章状态"></ren-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('api:shopArticle:save')" type="primary" @click="addOrUpdateHandle()">
            新增
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('api:shopArticle:delete')" type="danger" @click="deleteHandle()">
            删除
          </el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" stripe highlight-current-row
                @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle"
                style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="tile" label="标题" header-align="center" align="center" width="" show-overflow-tooltip></el-table-column>
        <el-table-column prop="subtitle" label="副标题" header-align="center" align="center" width="" show-overflow-tooltip></el-table-column>
        <el-table-column prop="img" label="封面" header-align="center" align="center" width="">
          <template slot-scope="{row,$index}">
            <!-- 图片展示 -->
            <el-popover trigger="click" placement="top" popper-class="popper">
              <img v-if="row.img" :src="row.img">
              <el-image v-if="row.img" slot="reference" :src="row.img" style="height: 50px;width: 50px;">
                <div slot="error">
                  暂无图片
                </div>
              </el-image>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="content" label="内容" header-align="center" align="center" width="" show-overflow-tooltip>
          <template slot-scope="{row}">
            <el-tag size="small" type="primary" style="cursor: pointer;" @click="showRichText(row.content)" v-if="row.content.length>30">点击查看</el-tag>
            <div v-else>暂无内容</div>
          </template>
        </el-table-column>
        <el-table-column prop="category" label="分类" header-align="center" align="center" sortable width="">
          <template slot-scope="{row,$index}">
            <el-tag v-if="row.type === 1" size="small" type="success">
              {{ $getDictLabel("category", row.category) }}
            </el-tag>
            <el-tag v-else size="small" type="info">{{
                $getDictLabel("category", row.category)
              }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="pub" label="文章状态" header-align="center" align="center" sortable width="">
          <template slot-scope="{row,$index}">
            <el-dropdown trigger="click" @command="dropdownCk">
              <div class="el-dropdown-link demonstration" >
                <el-tag v-if="row.pub === 1" size="small" type="success">
                  {{ $getDictLabel("pub", row.pub) }}
                </el-tag>
                <el-tag v-else size="small" type="info">{{
                    $getDictLabel("pub", row.pub)
                  }}
                </el-tag>
              </div>
              <el-dropdown-menu slot="dropdown" >
                <el-dropdown-item  v-for="(item,index) in getDictDataList('pub')" :key="index" :command="row.id+'?'+ item.dictValue">{{ $getDictLabel("pub", item.dictValue) }}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="创建日期" header-align="center" align="center"></el-table-column>
        <el-table-column label="操作" fixed="right" header-align="center" align="center" width="200">
          <template slot-scope="scope">
            <el-link v-if="$hasPermission('api:shopArticle:update')" type="primary"
                       @click="addOrUpdateHandle(scope.row.id)">修改
            </el-link>
            <el-link v-if="$hasPermission('api:shopArticle:delete')" type="primary"
                       @click="deleteHandle(scope.row.id)">删除
            </el-link>
          </template>
        </el-table-column>

      </el-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
                     layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
                     @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      <!--富文本显示-->
      <com-rich-text :visible.sync="showRich" :content="content"></com-rich-text>
    </div>

  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './shopArticleAddOrUpdate.vue'
import {getDictDataList} from "@/utils";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/api/shopArticle/page',
        getDataListIsPage: true,
        deleteURL: '/api/shopArticle',
        deleteIsBatch: true
      },
      showRich:false,                    //富文本显示
      content:"",                        //富文本内容
      dataForm: {
        id: '',                          //id
        category:'',                     //分类，公司介绍，酱酒工艺
        pub:'',                          //是否发布0未发布1发布
        tile:'',                         //文章标题
        subtitle:'',                     //文章副标题
        img:'',                          //封面
        content:'',                      //文章内容
        sort:'',                         //显示顺序
        productId:'',                    //关联商品ID
        productSpecsId:'',               //关联规格ID
      },
    }
  },
  components: {
    AddOrUpdate
  },
  created() {

  },
  methods: {
    getDictDataList,
    //富文本显示
    showRichText(content){
      this.showRich=true;
      this.content= content;
    },
    //快速修改是否隐藏评论状态
    dropdownCk(e){
      const value = e.split('?')
      const item = {id:  value[0], pub: value[1]}
      this.$http.put('/api/shopArticle', item).then(({data: res}) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.$message({
          message: this.$t('prompt.success'),
          type: 'success',
          duration: 500,
          onClose: () => {
            this.getDataList()
          }
        })
      }).catch(() => {
      })
    }}
}
</script>
<style lang="scss">
.ellipsis2 {
  /* //超出两行省略号 */
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.el-dropdown-link {
  cursor: pointer;
}
.demonstration {
  display: block;
}
</style>
